package com.mg.demo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

import com.ushaqi.zhuishushenqi.ZSPlugin;
import com.ushaqi.zhuishushenqi.interfaceutil.LoginListener;

/**
 * Created by John on 2018/4/19.
 */

public class MGTVActy extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout linearLayout = new LinearLayout(this);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        linearLayout.setLayoutParams(params);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        Button b = new Button(this);
        float density = getResources().getDisplayMetrics().density;
        int height = (int) (70 * density);
        final LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

        p.height = height;

        b.setLayoutParams(p);
        b.setText("未登录看书");
        linearLayout.addView(b);

        Button d = new Button(this);
        d.setLayoutParams(p);
        d.setText("默认Ticket登录看书");
        linearLayout.addView(d);

        final EditText d0 = new EditText(this);
        d0.setLayoutParams(p);
        d0.setHint("请输入TICKET");
        d0.setText("PHZW4350XQHUYRMT9A8C");
        linearLayout.addView(d0);

        Button d1 = new Button(this);
        d1.setLayoutParams(p);
        d1.setText("切换账号Ticket登录看书");
        linearLayout.addView(d1);

        Button e = new Button(this);
        e.setLayoutParams(p);
        e.setText("未登录打开书籍详情");
        linearLayout.addView(e);

        Button oneOpenDetail = new Button(this);
        oneOpenDetail.setLayoutParams(p);
        oneOpenDetail.setText("TICKET一打开书籍详情");
        linearLayout.addView(oneOpenDetail);

        Button twoOpenDetail = new Button(this);
        twoOpenDetail.setLayoutParams(p);
        twoOpenDetail.setText("TICKET二打开书籍详情");
        linearLayout.addView(twoOpenDetail);

        Button unLoginOpenBook = new Button(this);
        unLoginOpenBook.setLayoutParams(p);
        unLoginOpenBook.setText("未登录打开书");
        linearLayout.addView(unLoginOpenBook);


        Button oneOPenBook = new Button(this);
        oneOPenBook.setLayoutParams(p);
        oneOPenBook.setText("TICKET一打开书");
        linearLayout.addView(oneOPenBook);

        Button twoOpenBook = new Button(this);
        twoOpenBook.setLayoutParams(p);
        twoOpenBook.setText("TICKET二打开书");
        linearLayout.addView(twoOpenBook);

        Button unLoginOpenEpub = new Button(this);
        unLoginOpenEpub.setLayoutParams(p);

        unLoginOpenEpub.setText("未登录打开EPUB");
        linearLayout.addView(unLoginOpenEpub);
        unLoginOpenEpub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReader(MGTVActy.this, new LoginListener() {
                    @Override
                    public void onLogin() {
                        startActivity(new Intent(MGTVActy.this, AuthLoginActivity.class));
                    }
                }, "59913d9f28e7077d7ebb6a5e", "zhuixiaoshuo");
            }
        });

        Button oneOpenEpub = new Button(this);
        oneOpenEpub.setLayoutParams(p);
        oneOpenEpub.setText("TICKET一打开EPUB");
        linearLayout.addView(oneOpenEpub);

        oneOpenEpub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "2FPW3582XTPGVBGL234D", "59913d9f28e7077d7ebb6a5e", "zhuixiaoshuo");

            }
        });
        Button twoOpenEpub = new Button(this);
        twoOpenEpub.setLayoutParams(p);
        twoOpenEpub.setText("TICKET二打开EPUB");
        linearLayout.addView(twoOpenEpub);


        twoOpenEpub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "PHZW4350XQHUYRMT9A8C", "5990fda2a2ae1d826d951ca8", "zhuixiaoshuo");

            }
        });

        Button unLoginOpenCartoon = new Button(this);
        unLoginOpenCartoon.setLayoutParams(p);
        unLoginOpenCartoon.setText("未登录打开漫画");
        linearLayout.addView(unLoginOpenCartoon);


        Button oneOpenCartoon = new Button(this);
        oneOpenCartoon.setLayoutParams(p);
        oneOpenCartoon.setText("TICKET1打开漫画");
        linearLayout.addView(oneOpenCartoon);

        Button twoOenCartoon = new Button(this);
        twoOenCartoon.setLayoutParams(p);
        twoOenCartoon.setText("TICKET二打开漫画");
        linearLayout.addView(twoOenCartoon);


        Button myBook = new Button(this);
        myBook.setLayoutParams(p);
        myBook.setText("TICKET一的书籍");
        linearLayout.addView(myBook);

        Button myBook2 = new Button(this);
        myBook.setLayoutParams(p);
        myBook2.setText("TICKET二的书籍");
        linearLayout.addView(myBook2);

        ScrollView contentView = (ScrollView) getLayoutInflater().inflate(R.layout.mgtv, null, false);

        contentView.addView(linearLayout);
        setContentView(contentView);

        setContentView(contentView);

        unLoginOpenCartoon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReader(MGTVActy.this, new LoginListener() {
                    @Override
                    public void onLogin() {
                        startActivity(new Intent(MGTVActy.this, AuthLoginActivity.class));
                    }
                }, "59770f89a047e3f06829ef16", "zhuixiaoshuo");
            }
        });

        twoOpenBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "PHZW4350XQHUYRMT9A8C", "5775d4baf65d25e21ca75e19", "zhuixiaoshuo");

            }
        });
        oneOpenCartoon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "2FPW3582XTPGVBGL234D", "59770f89a047e3f06829ef16", "zhuixiaoshuo");

            }
        });
        twoOenCartoon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "PHZW4350XQHUYRMT9A8C", "597093ccde2d10232f77d321", "zhuixiaoshuo");

            }
        });


        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ZSPlugin.get().readBook(MGTVActy.this, new LoginListener() {
                    @Override
                    public void onLogin() {
                        startActivity(new Intent(MGTVActy.this, AuthLoginActivity.class));
                    }
                }, "zhuixiaoshuo");
            }
        });

        d.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ZSPlugin.get().readBookCarryTicket(MGTVActy.this, "2FPW3582XTPGVBGL234D", "zhuixiaoshuo");

            }
        });

        d1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String ticket = d0.getText().toString().trim();
                if (TextUtils.isEmpty(ticket)) {
                    Toast.makeText(getApplication(), "需要ticket", Toast.LENGTH_SHORT).show();
                    return;
                }
                ZSPlugin.get().readBookCarryTicket(MGTVActy.this, ticket, "zhuixiaoshuo");

            }
        });

        e.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                ZSPlugin.get().openBookDetails(MGTVActy.this, new LoginListener() {
                    @Override
                    public void onLogin() {
                        startActivity(new Intent(MGTVActy.this, AuthLoginActivity.class));
                    }
                }, "5530dd06423278526a2e8d75", "zhuixiaoshuo");
            }
        });


        oneOpenDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ZSPlugin.get().openBookDetailsCarryTicket(MGTVActy.this, "2FPW3582XTPGVBGL234D", "512199de221b4d2f30000100", "zhuixiaoshuo");
            }
        });

        twoOpenDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openBookDetailsCarryTicket(MGTVActy.this, "PHZW4350XQHUYRMT9A8C", "5abc4e5cae59aa7bea9b7570", "zhuixiaoshuo");

            }
        });

        unLoginOpenBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ZSPlugin.get().openReader(MGTVActy.this, new LoginListener() {
                    @Override
                    public void onLogin() {
                        startActivity(new Intent(MGTVActy.this, AuthLoginActivity.class));
                    }
                }, "516531015a29ee6a5e0000e1", "zhuixiaoshuo");
            }
        });
        oneOPenBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZSPlugin.get().openReaderCarryTicket(MGTVActy.this, "2FPW3582XTPGVBGL234D", "512199de221b4d2f30000100", "zhuixiaoshuo");

            }
        });

        myBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MGTVActy.this, MyBooListActivity.class);
                i.putExtra("ticket", "2FPW3582XTPGVBGL234D");
                startActivity(i);

            }
        });
        myBook2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MGTVActy.this, MyBooListActivity.class);
                i.putExtra("ticket", "PHZW4350XQHUYRMT9A8C");
                startActivity(i);
            }
        });


    }
}
